import 'dart:math';

import 'package:flutter/cupertino.dart';
import 'package:ball_lion/resources/colours.dart';
import 'package:ball_lion/utils/utils.dart';

import 'package:ball_lion/widgets/base/wqs_text.dart';

enum LabelType {
  king,
  viewpoint,
  viewpointRecord,
  planForm,
  planFormDetail,
  secret,
  planPack
}

class HistoryLabel extends StatelessWidget {
  const HistoryLabel.king(
      {super.key, required this.text, this.state, this.fontSize = 12})
      : type = LabelType.king,
        width = 50;
  const HistoryLabel.viewpoint(
      {super.key, this.state, this.fontSize = 12, this.width = 50})
      : type = LabelType.viewpoint,
        text = null;
  const HistoryLabel.viewpointRecord(
      {super.key, this.state, this.fontSize = 12, this.width = 50})
      : type = LabelType.viewpointRecord,
        text = null;
  const HistoryLabel.planForm(
      {super.key, this.text, this.state, this.width = 36, this.fontSize = 12})
      : type = LabelType.planForm;
  const HistoryLabel.planFormDetail(
      {super.key, this.state, this.width = 28, this.fontSize = 10})
      : type = LabelType.planFormDetail,
        text = null;
  const HistoryLabel.secret(
      {super.key, this.state, this.width = 36, this.fontSize = 12})
      : type = LabelType.secret,
        text = null;
  const HistoryLabel.planPack(
      {super.key, this.width = 36, this.fontSize = 12, this.text})
      : type = LabelType.planPack,
        state = null;

  final String? text;
  final int? state;
  final LabelType type;
  final double width;
  final double fontSize;

  @override
  Widget build(BuildContext context) {
    List<String> asset = List.generate(
        4,
        (index) =>
            "${type == LabelType.king ? "king_" : ""}history_label_$index.png");
    switch (type) {
      case LabelType.planPack:
        asset = ["plan_pack_history_label.png"];
        break;
      case LabelType.king:
        asset = List.generate(3, (index) => "king_history_label_$index.png");
        break;
      default:
        break;
    }
    List<Color> color = [
      type == LabelType.king ? Colours.orangeFF6E1D : Colours.main,
      Colours.grey62,
      Colours.blue2766D6,
      Colours.grey99
    ];
    List<String> labelText = [];
    List<String> viewpointText = ["红", "黑", "取消", "走", "2中1", "3中1", "3中2"];
    List<String> viewRecordText = ["红", "黑", "取消", "走", "1/2", "1/3", "2/3"];
    List<String> planFormText = ["命中", "未中"];
    List<String> planFormDetailText = ["红", "黑", "走"];
    int? index;
    int? textIndex;
    switch (type) {
      case LabelType.king:
        if (text!.contains("球票")) {
          index = 0;
        } else if (text == "预测未中") {
          index = 1;
        } else {
          index = 2;
        }
        break;
      case LabelType.viewpoint:
      case LabelType.viewpointRecord:
        labelText =
            (type == LabelType.viewpoint ? viewpointText : viewRecordText);
        textIndex = (state ?? 1) - 1;
        switch (state) {
          case 1:
          case 5:
          case 6:
          case 7:
            index = 0;
            break;
          case 2:
            index = 1;
            break;
          case 3:
            index = 3;
            break;
          case 4:
            index = 2;
            break;
        }
        break;
      case LabelType.planForm:
        labelText = planFormText;
        if (state == 2) {
          index = 0;
        } else if (state == 3) {
          index = 1;
        }
        break;
      case LabelType.planFormDetail:
        labelText = planFormDetailText;
        if (state == 2) {
          index = 0;
        } else if (state == 3) {
          index = 1;
        } else if (state == 4) {
          index = 2;
        }
        break;
      case LabelType.secret:
        labelText = planFormText;
        if (state == 1) index = 0;
        break;
      case LabelType.planPack:
        index = 0;
        break;
    }
    return (index == null && text == null)
        ? Container()
        : Stack(alignment: AlignmentDirectional.center, children: [
            Image.asset(width: width, Utils.getImgPath(asset[index!])),
            Transform.rotate(
                angle: -pi / 6,
                child: QsText(text ?? labelText[textIndex ?? index],
                    needCenter: true, fontSize: fontSize, color: color[index]))
          ]);
  }
}
